package com.dfbz.demo03_equals方法;

import java.util.Objects;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo01 {


    public static void main(String[] args) {

       Person p1 = new Person("小明", 30);
        Person p2 = new Person(new String("小明"), 30);

        boolean flag = p1.equals(p2);

        System.out.println(flag);

    }

    public static void test(String[] args) {

        Object obj = new Object();
        A a = new A();

        boolean flag1 = obj.equals(a);
        boolean flag2 = obj == a;

        System.out.println(flag1);
        System.out.println(flag2);
    }
}


class Person {
    private String name;
    private int age;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age &&
                Objects.equals(name, person.name);
    }


    /*   public boolean equals(Object obj) {
        Person p = (Person) obj;

        if (this.name.equals(p.getName()) && this.age == p.getAge()) {
            return true;
        } else {
            return false;
        }
    }*/

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

class A {
}
